package com.ruoyi.system.service.gallery.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.construction.ConstructionInfo;
import com.ruoyi.system.domain.gallery.GalleryComment;
import com.ruoyi.system.domain.gallery.GalleryInfo;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.SupplierInfo;
import com.ruoyi.system.mapper.gallery.GalleryCommentMapper;
import com.ruoyi.system.mapper.gallery.GalleryInfoMapper;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.SupplierInfoMapper;
import com.ruoyi.system.service.gallery.GalleryCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 图库评论Service业务层处理
 *
 * @author 张少丛
 * @date 2020-12-02
 */
@Service
public class GalleryCommentServiceImpl implements GalleryCommentService
{
    @Autowired
    private GalleryCommentMapper galleryCommentMapper;

    @Autowired
    private SupplierInfoMapper supplierInfoMapper;

    @Autowired
    private GalleryInfoMapper galleryInfoMapper;

    /**
     * 查询图库评论
     *
     * @param galleryCommentId 图库评论ID
     * @return 图库评论
     */
    @Override
    public GalleryComment selectGalleryCommentById(Long galleryCommentId)
    {
        return galleryCommentMapper.selectGalleryCommentById(galleryCommentId);
    }

    /**
     * 查询图库评论列表
     *
     * @param galleryComment 图库评论
     * @return 图库评论
     */
    @Override
    public List<GalleryComment> selectGalleryCommentList(GalleryComment galleryComment,Long userId)
    {
        SupplierInfo supplierInfo = new SupplierInfo();
        supplierInfo.setCustomerId(userId);
        supplierInfo.setSupplierTypeform(2);
        // 创建集合储存供应商ID
        List<Long> supplierIds = new ArrayList<Long>();
        // 创建集合储存施工队人员ID
        List<Long> galleryInfoIds = new ArrayList<Long>();
        // 根据用户ID查询供应商信息
        List<SupplierInfo> supplierInfoList = supplierInfoMapper.selectSupplierInfoByUserId(supplierInfo);
        if(supplierInfoList.size()>0){
            for (SupplierInfo supplier : supplierInfoList) {
                supplierIds.add(Long.valueOf(supplier.getSupplierId()));
            }
        }else{
            supplierIds.add(Long.valueOf(-1));
        }
        // 创建人员实体类
        GalleryInfo  galleryInfo = new GalleryInfo();
        galleryInfo.setSupplierIds(supplierIds);
        // 根据供应商ID查询所有人员信息
        List<GalleryInfo> galletyInfoList = this.galleryInfoMapper.selectGalleryInfoList(galleryInfo);
        if(galletyInfoList.size() > 0){
            // 添加到集合中
            for (GalleryInfo gInfo : galletyInfoList) {
                galleryInfoIds.add(gInfo.getGalleryInfoId());
            }
        }else {
            galleryInfoIds.add(Long.valueOf(-1));
        }
//        galleryComment.setGalleryInfoIds(galleryInfoIds);
        galleryComment.setGalleryInfoIds(null);
        List<GalleryComment> galleryComments = galleryCommentMapper.selectGalleryCommentList(galleryComment);
        return galleryComments;
    }

    /**
     * 新增图库评论
     *
     * @param galleryComment 图库评论
     * @return 结果
     */
    @Override
    public int insertGalleryComment(GalleryComment galleryComment)
    {
        return galleryCommentMapper.insertGalleryComment(galleryComment);
    }

    /**
     * 修改图库评论
     *
     * @param galleryComment 图库评论
     * @return 结果
     */
    @Override
    public int updateGalleryComment(GalleryComment galleryComment)
    {
        return galleryCommentMapper.updateGalleryComment(galleryComment);
    }

    /**
     * 批量删除图库评论
     *
     * @param galleryCommentIds 需要删除的图库评论ID
     * @return 结果
     */
    @Override
    public int deleteGalleryCommentByIds(Long[] galleryCommentIds)
    {
        return galleryCommentMapper.deleteGalleryCommentByIds(galleryCommentIds);
    }

    /**
     * 删除图库评论信息
     *
     * @param galleryCommentId 图库评论ID
     * @return 结果
     */
    @Override
    public int deleteGalleryCommentById(Long galleryCommentId)
    {
        return galleryCommentMapper.deleteGalleryCommentById(galleryCommentId);
    }
}
